package com.bike.controller.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bike.controller.BaseController;
import com.bike.entity.HhBusiness;
import com.bike.entity.HhBusinessUser;
import com.bike.service.impl.HhAgentServiceImpl;
import com.bike.service.impl.HhBusinessServiceImpl;
import com.bike.service.impl.HhBusinessUserServiceImpl;
import com.bike.service.impl.HhOrderServiceImpl;
import com.bike.util.PageData;

 
@Controller
@RequestMapping(value="/apiBusiness")
public class HhApiBusinessController extends BaseController {
	
		@Autowired
		private HhAgentServiceImpl  hhAgentService;
		@Autowired
		private HhOrderServiceImpl  orderServiceImpl;
		@Autowired
		private HhBusinessUserServiceImpl  businessUserServiceImpl;
		@Autowired
		private HhBusinessServiceImpl  businessServiceImpl;
		/**
		 * 列表查询(或根据条件)
		 */
		@RequestMapping("list")
		@ResponseBody
		public PageData list(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			Long userId=pd.getLong("userId");
			HhBusinessUser businessUser=(HhBusinessUser) request.getAttribute("businessUser");
			pd.put("userId", null);
			pd.put("businessId", businessUser.getBusinessId());
			List<HhBusinessUser> businessUserList=businessUserServiceImpl.listAll(pd);
			
			PageData resultPd=getSuccessPd();
			resultPd.put("rows",businessUserList );
			
			return resultPd;
		}
		/**
		 * 打烊
		 */
		@RequestMapping("close")
		@ResponseBody
		public PageData close(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			
			int disable=pd.getInteger("disable");
			Long userId=pd.getLong("userId");
			HhBusinessUser businessUser=(HhBusinessUser) request.getAttribute("businessUser");
			HhBusiness business=businessServiceImpl.selectByHhBusinessId(businessUser.getBusinessId());
			business.setDisable(disable);
			businessUserServiceImpl.updateClose(business);
			PageData resultPd=getSuccessPd();
			resultPd.put("disable", disable);
			return resultPd;
		}
	 
		
		
		
		
		
}
